package com.fernfx.xingtan.my.ui;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.fernfx.xingtan.R;
import com.fernfx.xingtan.common.pullrefresh.PullToRefreshActivity;
import com.fernfx.xingtan.common.base.BaseActivity;
import com.fernfx.xingtan.my.contract.MyPocketMoneyContract;
import com.fernfx.xingtan.my.entity.MyPocketMoneyEntity;
import com.fernfx.xingtan.my.presenter.MyPocketMoneyPresenter;

import java.io.Serializable;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/8/20.
 * 零花钱
 */

public class MyPocketMoneyActivity extends BaseActivity implements View.OnClickListener, MyPocketMoneyContract.View{

    @BindView(R.id.tv_refund_project_title)
    TextView refundProjectTitleTv;
    @BindView(R.id.money_tv)
    TextView moneyTv;

    //presenter
    private MyPocketMoneyContract.Presenter presenter;

    public static void start(Context context) {
        Intent intent = new Intent(context, MyPocketMoneyActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_my_pocket_money;
    }

    @Override
    protected void initView() {
        setToolbarTitle("零钱");
        //设置title
        refundProjectTitleTv.setVisibility(View.VISIBLE);
        refundProjectTitleTv.setText("零钱明细");
    }

    @Override
    protected void initData() {
        presenter = new MyPocketMoneyPresenter();
        presenter.init(this);
        requestArgsMap.clear();
        presenter.request(requestArgsMap);
    }

    @OnClick({R.id.tv_refund_project_title})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_refund_project_title:
                PullToRefreshActivity.start(mContext,new MyPocketMoneyCallback());
                break;
        }
    }

    @Override
    public BaseActivity getActivity() {
        return this;
    }

    @Override
    public void displayMoney(MyPocketMoneyEntity myPocketMoneyEntity) {
        if (myPocketMoneyEntity == null) {
            return;
        }
        if (myPocketMoneyEntity.getObj() == null || TextUtils.isEmpty(myPocketMoneyEntity.getObj().getAmount())) {
            moneyTv.setText("0元");
        } else {
            moneyTv.setText(myPocketMoneyEntity.getObj().getAmount() + "元");
        }
    }

    /*
     *实现公共的接口
     */
    public class MyPocketMoneyCallback implements PullToRefreshActivity.CallBack{

        @Override
        public Map<String, Object> getRequestArgsMap() {
            requestArgsMap.clear();
            requestArgsMap.put("pageNo",1);
            requestArgsMap.put("pageSize",10);
            requestArgsMap.put("orderBy","create_time");
            requestArgsMap.put("order","desc");
            return requestArgsMap;
        }

        @Override
        public String getRequestUrl() {
            return "wallet/getPennyList";
        }

        @Override
        public boolean getIsGet() {
            return true;
        }

        @Override
        public int getStatus() {
            return PullToRefreshActivity.MY_POCKET_MONEY_STATUS;
        }

        @Override
        public String getTitle() {
            return "零钱明细";
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            presenter.detachView();
            presenter = null;
        }
    }
}
